package user

import (
	"context"
	"fmt"
	"github.com/jinzhu/copier"

	"large-model-platform-backend/internal/svc"
	"large-model-platform-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List(req *types.Request1) (resp *types.UserResp, err error) {
	model := l.svcCtx.UserModel
	all, err := model.FindAll(l.ctx)

	var users []types.UserData
	for _, user := range all {
		u := types.User{}
		copier.Copy(&u, &user)
		u.Password = "*******"
		users = append(users, types.UserData{
			ID:           user.ID.Hex(),
			User:         u,
			ChatSessions: nil,
		})
	}
	fmt.Println(users)
	return &types.UserResp{
		Result: types.Result{Code: 200},
		Data:   users,
	}, nil
}
